/*
 * 新增同类医嘱单JS
 */
var GLOBALSUN; //全局参数
$(function(){
	addSameTab();
})

//获取当前类型topTab
 GLOBALSUN= {
		
	"Jianyan":{text:"检验",tpldiv:"add_jianyan_div.html",inittable:"JianyanTable"},
	"Jiancha":{text:"检查",tpldiv:"add_jiancha_div.html",inittable:"JianchaTable"},
    "Xiyao":{text:"西成药",tpldiv:"add_xiyao_div.html",inittable:"westMedicineTable"},
    "Zhongyao":{text:"中草药",tpldiv:"add_zhongyao_div.html",inittable:"chinaMedicineTable"},
    "Shoushu":{text:"手术",tpldiv:"add_shoushu_div.html",inittable:"shoushuTable"},
    "Zhiliao":{text:"治疗及其它",tpldiv:"add_zhiliao_div.html",inittable:"zhiliaoTable"},
    "Cailiao":{text:"材料",tpldiv:"add_cailiao_div.html",inittable:"cailiaoTable"}
	
}
//点击新增同类医嘱单增加页签
function addSameTab(){
	$("#new_similar").on("click", function() {
		debugger;
		var number = getSameNumber();
		//创建新的href
		var newlihref = topTab +getSameNumber();
		var newli = '<li><a href="#'+newlihref+'" data-toggle="tab" onclick="typeClick(\''+topTab+'\')">'+GLOBALSUN[topTab]['text']+'('+number+')</a><div class="messageSign"> <label class="label-normal"></label></div></li>'
		$(".new_similar").before(newli);
		
		var data={};
		data.tabId = newlihref; //tabid
		data.tableId = topTab+"_table"+"_"+number;
		data.tbodyId = topTab+"_tbody"+"_"+number;
		tplloadDiv(data);
	})
}
//加载tablediv
function tplloadDiv(data){
	laytplUrl_T(myurl + "/module/"+GLOBALSUN[topTab]['tpldiv'],data, function(data, html) {
		$("#order_tab").append(html);
		//初始化
		$(".tscf").select2();
		$(".xmgs").select2();
		$(".zfbs").select2();
		iChenckInit($("#" + data.tabId + " thead").find("input[type='checkbox']"));
		
		$('#new_order_list a[href="#'+data.tabId+'"]').trigger("click");
		debugger;
		eval(GLOBALSUN[topTab]["inittable"]+"("+JSON.stringify(data)+")");
	});
}

//计算同类的个数
function getSameNumber(){
	var num=0
	$("#new_order_list li").find("a").each(function(i,e){
		if($(e).attr("href").indexOf(topTab) >-1){
			num++;
		}
	})
	return num;
}






